package com.rlyy.basic.resolver.exception;

import com.rlyy.common.enums.CommonEnum;
import com.rlyy.common.response.Result;
import com.rlyy.common.response.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.Ordered;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 *
 * @author yuanqinglong
 * @since 2020/11/30 9:46
 */
@ControllerAdvice
public class LastExceptionHandler implements Ordered{

    private static final Logger LOG = LoggerFactory.getLogger(LastExceptionHandler.class);

    /**
     * 参数解析异常
     *
     * @param exception 异常信息
     * @return 封装错误返回数据
     */
    @ExceptionHandler(Exception.class)
    public Result exception(Exception exception) {
        LOG.error("服务器异常：", exception);
        return ResultUtil.error(CommonEnum.SERVER_IS_BUSY);
    }



    @Override
    public int getOrder() {
        return Ordered.LOWEST_PRECEDENCE;
    }
}
